import { createTransport } from 'nodemailer';
import { sendcode, adminLoginCode } from './mailTemplate/index';
const user = 'keke7426e@163.com';
const name = '一柯小白菜';
const pass = 'WAAXPBTEEPSZFQIF';
const smtpTransport = createTransport({
	host: 'smtp.163.com', //pop、smtp、imap
	port: 465,
	secure: true,
	auth: {
		user,
		pass,
	},
});

export const sentMail = ({ to, title, text, html }) => {
	return smtpTransport.sendMail({
		from: `${name} <${user}>`,
		to,
		subject: title,
		text,
		html,
	});
};

export const sendCodeMail = ({ to, time, code }) => {
	return sentMail({
		to,
		title: '验证码',
		html: sendcode({ code, time, username: to }),
	});
};

export const sendAdminCode = ({ to, code }) => {
	return sentMail({
		to,
		title: '管理员密码',
		html: adminLoginCode({ code, username: to }),
	});
};
